home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / trojka.tgz / trojka.tar / trojka / screen.c < prev    next >
C/C++ Source or Header  |  1994-02-25  |  7KB  |  448 lines

  1. /*
  2.  *    @(#) screen.c -- Screen oriented routines for TROJKA
  3.  *    created:    4.iii.1992
  4.  *    last update:     16.iv.1992
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9.  
  10. #include "sys_custom.h"
  11. #include "trojka.h"
  12. #include "screen.h"
  13. #include "hiscore.h"
  14.  
  15. int    makeblock(),     wipeblock(),     makestars(),
  16.     showscore(),     showtrojka(),     showspeed(),
  17.     showmesg(),    showgameover(),
  18.     titlescreen(),    listscores(),
  19.     build(),     redraw(),    drawfield(),
  20.     statistics(),     selectspeed(),
  21.         getname(),    dropchar(),    backspace();
  22.  
  23. extern struct scorefile *sfile;
  24.  
  25. extern flag
  26.     quit;         /* all defined in trojka */
  27.  
  28. extern int
  29.     block_count[],
  30.     xloc[],
  31.     yloc[],
  32.     blockwidth,
  33.     stacklevel,
  34.     position,
  35.     x_min,
  36.     x_max,
  37.     statx,
  38.     speed;
  39.  
  40.  
  41. extern unsigned long
  42.     score,
  43.     wipes,
  44.     blocks;
  45.  
  46. extern char field[VIRT_XSIZE][VIRT_YSIZE];
  47.  
  48. static char TITLE[7][40] = {
  49.     "                       **",
  50.     "*****  ****    ***   *   *  *  *    *  ",
  51.     "  *    *   *  *   *  *  **  * *    * * ",
  52.     "  *    ****   *   *  * * *  **    *   *",
  53.     "  *    *      *   *  **  *  * *   *****",
  54.     "  *    *       ***   *   *  *  *  *   *",
  55.     "  T      R      O      J     K      A  "
  56. };
  57.  
  58.  
  59. static char mesg[MESGS][40] = {
  60.     "You're doin' well",
  61.     "You're playing ok",
  62.     "You're doin' fine",
  63.     "You're playing good",
  64.     "You're playing great",
  65.     "You're playing very good",
  66.     "You're really are good at this",
  67.     "You're a champion",
  68.     "You're a trojka-professional",
  69.     "You've played this before, haven't ya?",
  70.     "Hey, I hope you're not cheating!",
  71.     "What a magnificent score",
  72.     "You're kinda addicted...",
  73.     "You're a MEGA-player",
  74.     "What time is it, by the way?",
  75.     "You're a trojka-czar",
  76.     "I'm very tired",
  77.     "You must be paranoid..",
  78.     "I give up giving comments. Enjoy!"
  79. };
  80.  
  81. static char block80[BLOCKS+1][5] =
  82. {
  83.     "    ",
  84.     "OOOO",
  85.     "||||",
  86.     "XXXX",
  87.     "%%%%",
  88.     "$$$$"
  89. }; /* used in mono */
  90.  
  91.  
  92. int makeblock(x, y, shape)        /* create a block    */
  93. int x, y, shape;
  94. {
  95.     movexy(xloc[x], yloc[y]);
  96.     qprintf("%4s",block80[shape]);
  97. }
  98.  
  99.  
  100. int wipeblock(x, y)        /* remove block */
  101. int x, y;
  102. {
  103.     movexy(xloc[x], yloc[y]);
  104.     qprintf(SPACE80);
  105. }
  106.  
  107.  
  108. int makestars(x, y)        /* show stars */
  109. int x, y;
  110. {
  111.     movexy(xloc[x], yloc[y]);
  112.     qprintf(WIPE80);
  113. }
  114.  
  115.  
  116. int showscore()
  117. {
  118.     movexy(SCORE_X, SCORE_Y+1);
  119.     qprintf("%7lu",score);
  120.     refresh();
  121. }
  122.  
  123.  
  124. int showtrojka(bonus)
  125. int bonus;
  126. {
  127.     movexy(x_min, BONUS_Y);
  128.     qprintf("TROJKA!  %5lu",
  129.         (unsigned long)(1111*bonus)
  130.     );
  131.     refresh();
  132.     delay(1000);
  133.     movexy(x_min, BONUS_Y); qprintf("              ");
  134.     refresh();
  135. }
  136.  
  137.  
  138. int showspeed(s)
  139. int s;
  140. {
  141.     movexy(SPEED_X+3, SPEED_Y+1);    qprintf("%u",s);
  142.         refresh();
  143. }
  144.  
  145.  
  146. int showmesg(n)
  147. int n;
  148. {
  149.     movexy((80 - strlen(mesg[n])) / 2, MESG_Y);
  150.     qprintf("%s",mesg[n]);
  151.         refresh();
  152. }
  153.  
  154.  
  155. int wipemesg()
  156. {
  157.     movexy(1, MESG_Y);
  158.     clreol();
  159.         refresh();
  160. }
  161.  
  162.  
  163. int showgameover()
  164. {
  165.     movexy(x_min,10);
  166.     qprintf(" G A M E    O V E R ");
  167.         refresh();
  168.     delay(1500);
  169.  
  170. }
  171.  
  172.  
  173. int handletrojka(trojka_count)
  174. int trojka_count;
  175. {
  176.     showtrojka(trojka_count);
  177.     score += (unsigned long)(trojka_count * 1111);
  178.     showscore();
  179. }
  180.  
  181.  
  182. int titlescreen()            /* title screen */
  183. {
  184.     char c;
  185.     int i;
  186.  
  187.  
  188.     clear_scr();
  189.  
  190.     for(i = 0; i < 7;i++) {
  191.         movexy(1,i +6);
  192.         qprintf("%s",TITLE[i]);
  193.     }
  194.     movexy(1,i + 13);
  195.     qprintf("KEEP PLAYING TROJKA");
  196.  
  197.     readscores();    /* re-read scores */
  198.     listscores();
  199.     movexy(1,1);
  200.     refresh();
  201.     killkeys();
  202.     c = getch();
  203.  
  204.     if(c == QUIT)
  205.         quit = TRUE;
  206.  
  207.     clear_scr();
  208. }
  209.  
  210.  
  211. int listscores()
  212. {
  213.     int j;
  214.     flag hilite;
  215.  
  216.     struct scorefile *eof, *i;
  217.  
  218.     eof = &sfile[NUMSCORES-1];
  219.     j = 0;
  220.     hilite = 0;
  221.  
  222.     movexy(HISCORE_X,1);    qprintf("Best Trojka-Czars");
  223.  
  224.     for(i=sfile; i<eof; i++) {
  225.         if (j == position-1) {
  226.             hilite = 1;
  227.             standout();
  228. /* hilight */
  229.         }
  230.         movexy(HISCORE_X, j+3);
  231.         qprintf("%-22s %7lu %3d",
  232.             i->name,
  233.             i->points,
  234.             i->stage
  235.         );
  236.         if(hilite == 1) {
  237.             standend();
  238. /* unhilight */
  239.             hilite = 0;
  240.         }
  241.         j++;
  242.     }
  243.     if(position >= NUMSCORES) {
  244.         movexy(HISCORE_X, 24);
  245.         qprintf("%-22s %7lu %3d",
  246.             "You",
  247.             score,
  248.             speed
  249.         );    
  250.     }
  251. }
  252.  
  253.  
  254. int build()
  255. {
  256.     int x, y, left, right;
  257.  
  258.     left = x_min - 1;
  259.     right = x_max + blockwidth;
  260.  
  261.     clear_scr();
  262.  
  263.     for(y = SCR_TOP + 1; y <= BOTTOM; y++) {
  264.         movexy(left, y);
  265.         qprintf("#");
  266.         movexy(right, y);
  267.         qprintf("#");
  268.     }
  269.     for(x = left; x <= right; x++)
  270.     {
  271.         movexy(x, BOTTOM + 1);
  272.         qprintf("#");
  273.     }
  274.  
  275.     movexy(SCORE_X, SCORE_Y);    qprintf("-SCORE-");
  276.     movexy(SPEED_X, SPEED_Y);    qprintf("-SPEED-");
  277.     movexy(statx, SUM_Y);        qprintf("S U M");
  278.     movexy(statx, WIPES_Y);        qprintf("* * *");
  279.     movexy(statx, 1);        qprintf("Statistics");
  280.     for(y = 0; y < BLOCKS; y++) {
  281.         movexy(statx, (y * 2) + 3);
  282.         qprintf("%4s",block80[y+1]);
  283.     }
  284.     movexy(SPEED_X+3, SPEED_Y+1);    qprintf("%u",speed);
  285.     refresh();
  286. }
  287.  
  288.  
  289. int redraw()
  290. {
  291.     int x, y, left, right;
  292.  
  293.     left = x_min - 1;
  294.     right = x_max + blockwidth;
  295.  
  296.     clear_scr();
  297.  
  298.     for(y = SCR_TOP + 1; y <= BOTTOM; y++) {
  299.         movexy(left, y);
  300.         qprintf("#");
  301.         movexy(right, y);
  302.         qprintf("#");
  303.     }
  304.     for(x = left; x <= right; x++)
  305.     {
  306.         movexy(x, BOTTOM + 1);
  307.         qprintf("#");
  308.     }
  309.  
  310.     movexy(SCORE_X, SCORE_Y);    qprintf("-SCORE-");
  311.     movexy(SPEED_X, SPEED_Y);    qprintf("-SPEED-");
  312.     movexy(statx, SUM_Y);        qprintf("S U M");
  313.     movexy(statx, WIPES_Y);        qprintf("* * *");
  314.     movexy(statx, 1);        qprintf("Statistics");
  315.     for(y = 0; y < BLOCKS; y++) {
  316.         movexy(statx, (y * 2) + 3);
  317.         qprintf("%4s",block80[y+1]);
  318.     }
  319.     drawfield();
  320.     refresh();
  321. }
  322.  
  323.  
  324. int drawfield()
  325. {
  326.     int x,y;
  327.         
  328.     for(x = 0; x < VIRT_XSIZE;x++)
  329.         for(y = PLM_TOP; y >= PLM_BOTTOM; y--)
  330.             makeblock(x,y,field[x][y]);
  331. }
  332.  
  333.  
  334. int statistics()
  335. {
  336.     int y, perc, x;
  337.  
  338.     x = statx + 6;
  339.  
  340.     movexy(statx, WIPES_Y+1);    qprintf("%5lu",wipes);
  341.     movexy(statx, SUM_Y+1);        qprintf("%5lu",blocks);
  342.  
  343.     for(y = 0; y < BLOCKS; y++) {
  344.         perc = (block_count[y] * 100) / blocks;
  345.         movexy(x, (( y * 2 ) + 3) );
  346.         qprintf("%4d %%", perc);
  347.     }
  348.     refresh();
  349. }
  350.  
  351.  
  352. int selectspeed()    /* get starting speed */
  353. {
  354.     char c;
  355.  
  356.     movexy(10, 12);
  357.     qprintf("Select game-speed (0...9) --->");
  358.     refresh();
  359.     killkeys();            /* flush keyboard buffer */
  360.     c = getch();
  361.     if (c == QUIT)        /* if QUIT-key is pressed.. */
  362.         quit = TRUE;        /* ..quit the game        */
  363.     else {
  364.         if((c >= '0') && (c <= '9'))
  365.             return c-'0';
  366.         return 5 ;
  367.     }
  368. }
  369.  
  370.  
  371. int getname(tag)
  372. char tag[];
  373. {
  374.     int x, xstart, name_len;
  375.     char c;
  376.  
  377.     name_len = 20;
  378.     x = c = 0;
  379.     xstart = (80-name_len) / 2;
  380.  
  381.     clear_scr(); 
  382.  
  383.     movexy(xstart, SCORE_Y);
  384.     qprintf("Score: %7lu", score);
  385.     movexy(xstart, SCORE_Y + 3);
  386.     qprintf("Enter your name please:");
  387.     movexy(xstart, TAG_Y);
  388.     qprintf("....................");
  389.     movexy(xstart + x, TAG_Y);
  390.     refresh();
  391.  
  392.     killkeys();
  393.     c = getch();
  394.  
  395.     movexy(26,SCORE_Y); clreol();
  396.     movexy(26,SCORE_Y + 3); clreol();
  397.     refresh();
  398.  
  399.     while((c != CR) && (c != LF)) {
  400.         movexy(xstart + x, TAG_Y);
  401.         refresh(); 
  402.         if ((c >= ' ') && (c <= '~') && (x < name_len)) {
  403.             dropchar(xstart + x, (tag[x] = c));
  404.             x++;
  405.         } else if((c == BACKSP) && (x > 0)) {
  406.                 x--;
  407.                 backspace(xstart + x, tag[x]);
  408.                 tag[x] = '\0';
  409.                 movexy(xstart + x, TAG_Y);
  410.                 qprintf(".");
  411.                 movexy(xstart + x, TAG_Y);
  412.                 refresh();
  413.             }
  414.         c = getch();
  415.     }
  416.     tag[x] = '\0';
  417.     return(x);
  418. }
  419.  
  420.  
  421. int dropchar(x,c)
  422. int x;
  423. char c;
  424. {
  425.     int y;
  426.  
  427.     for(y = SCR_TOP + 1; y <= TAG_Y; y++) {
  428.         movexy(x, y-1);        qprintf(" ");
  429.         movexy(x, y);        qprintf("%c",c);
  430.         refresh();
  431.     }
  432. }
  433.  
  434.  
  435. int backspace(x, c)
  436. int x;
  437. char c;
  438. {
  439.     int y;
  440.  
  441.     for(y = TAG_Y; y < SCR_BOT - 1; y++) {
  442.         movexy(x, y);        qprintf("%c",c);
  443.         refresh();
  444.         movexy(x, y);        qprintf(" ");
  445.         refresh();
  446.     }
  447. }
  448.